﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace QLChoDiaOc.Tables
{
    class DiaOc
    {
        QLChoDiaOcEntities m_entities = new QLChoDiaOcEntities();
        List<DIAOC> m_listDiaOc;

        DiaOc()
        {
            m_listDiaOc = m_entities.DIAOCs.ToList();
        }

        public void InsertDiaOc(string MaDiaOc, string MaKH, string MaLoaiDiaOc, string SoNha, string Duong, string Quan,
                                float DienTichDat, float DienTichSuDung, string ViTri, string HuongNha, string MoTa, int TinhTrang)
        {
            try
            {
                DIAOC m_diaoc = new DIAOC();
                m_diaoc.MaDiaOc = MaDiaOc;
                m_diaoc.MaKH = MaKH;
                m_diaoc.MaLoaiDiaOc = MaLoaiDiaOc;
                m_diaoc.SoNha = SoNha;
                m_diaoc.Duong = Duong;
                m_diaoc.Quan = Quan;
                m_diaoc.DienTichDat = DienTichDat;
                m_diaoc.DienTichSuDung = DienTichSuDung;
                m_diaoc.ViTri = ViTri;
                m_diaoc.HuongNha = HuongNha;
                m_diaoc.MoTa = MoTa;
                m_diaoc.TinhTrang = TinhTrang;

                //m_listDiaOc.Add(m_diaoc);
                m_entities.AddToDIAOCs(m_diaoc);
                m_entities.SaveChanges();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Thông Báo");
            }
        }

        public void UpdateDiaOc(string MaDiaOc, string MaKH, string MaLoaiDiaOc, string SoNha, string Duong, string Quan,
                                float DienTichDat, float DienTichSuDung, string ViTri, string HuongNha, string MoTa, int TinhTrang)
        {
            try
            {
                DIAOC m_diaoc = m_entities.DIAOCs.First(i => i.MaDiaOc == MaDiaOc);
                m_diaoc.MaKH = MaKH;
                m_diaoc.MaLoaiDiaOc = MaLoaiDiaOc;
                m_diaoc.SoNha = SoNha;
                m_diaoc.Duong = Duong;
                m_diaoc.Quan = Quan;
                m_diaoc.DienTichDat = DienTichDat;
                m_diaoc.DienTichSuDung = DienTichSuDung;
                m_diaoc.ViTri = ViTri;
                m_diaoc.HuongNha = HuongNha;
                m_diaoc.MoTa = MoTa;
                m_diaoc.TinhTrang = TinhTrang;
                m_entities.SaveChanges();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Thông Báo");
            }
        }

        public void DeteleDiaOc(string MaDiaOc)
        {
            try
            {
                DIAOC m_diaoc = m_entities.DIAOCs.First(i => i.MaDiaOc == MaDiaOc);
                m_entities.DIAOCs.DeleteObject(m_diaoc);
                m_entities.SaveChanges();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Thông Báo");
            }

            //var list = from d in m_entities.DIAOCs
            //           where d.DienTichDat > 0
            //           select d.MaDiaOc;
            //List<String> ll = list.ToList();
        }


    }
}
